package com.hyz.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hyz.pojo.assetImport.AssetImport;
import com.hyz.pojo.assetImport.AssetImportResultEnum;
import com.hyz.service.AssetImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author HGD
 * @date 2022/10/3 20:34
 */
@RestController
@RequestMapping("/assetImport")
public class AssetImportController {
    @Autowired
    private AssetImportService service;

    @PostMapping("/getAssetImportsByAssetManagerId")
    public List<AssetImport> getAssetImportsByAssetManagerId(@RequestBody Long assetManagerId) {
        LambdaQueryWrapper<AssetImport> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AssetImport::getAssetManagerId, assetManagerId);
        return service.list(wrapper);
    }

    @PostMapping("/getAssetImportsByRepositoryId")
    public List<AssetImport> getAssetImportsByRepositoryId(@RequestBody Long repositoryId) {
        LambdaQueryWrapper<AssetImport> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(AssetImport::getRepositoryId, repositoryId)
                .eq(AssetImport::getResult, AssetImportResultEnum.CREATE);
        return service.list(wrapper);
    }

}
